<template>
  <div class="app-container">
    <div class="searchform">
      <el-form
        ref="search"
        :model="search"
        size="mini"
        label-width="90px"
      >
        <el-row :gutter="6">

          <el-col :xs="24" :sm="8" :md="6">
            <el-form-item prop="file_name" label="附件名称">
              <el-input
                v-model="search.file_name"
                placeholder="附件名称"
                clearable
              />
            </el-form-item>
          </el-col>
          <div style="text-align:right">
            <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询</el-button>
            <el-button icon="el-icon-refresh" @click="resetForm('search')">重置</el-button>
          </div>
        </el-row>
      </el-form>
    </div>

    <div class="table">
      <div class="tableHead">
        <div class="tabletitle">列表</div>
        <div class="btnGroup">
          <el-button-group>
          <el-button type="primary" icon="el-icon-upload2" @click="fileUpload">新增</el-button></el-button-group>
        </div>
      </div>
      <baseTable ref="table" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle">
        <el-table-column type="index" label="序号" min-width="50"/>
        <el-table-column :show-overflow-tooltip="true" prop="file_upload_info_id" label="附件id" min-width="150"/>
        <el-table-column prop="bill_type" label="单据类型" min-width="150"/>
        <el-table-column prop="bill_id" label="单据id" min-width="150"/>
        <el-table-column prop="file_name" label="附件名称" min-width="150"/>
        <el-table-column prop="file_size" label="附件大小" min-width="150"/>
        <el-table-column prop="file_id" label="附件地址" min-width="150"/>
        <el-table-column prop="CREATED_AT" label="创建时间" min-width="150"/>
        <el-table-column :formatter="filterCode" prop="is_valid" label="状态" min-width="100" type="1001"/>
      </BaseTable>
    </div>
    <el-dialog v-dialogDrag v-if="dialogVisible" ref="fileDialog" :visible.sync="dialogVisible" :close-on-click-modal="false" title="附件新增" width="60%">
      <Upload :multiple="true" accept=".jpg,.png" action-type="icon" @uploaded="onCoverUpload"/>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getFileList } from '@/api/login.js'
import formMixins from '@/mixins/formMixins'
import { mapGetters } from 'vuex'
import moment from 'moment'
import _ from 'lodash'
import Upload from '@/components/uploads/Upload'
import BaseTable from '@/components/BaseTable'

export default {
  name: 'FileQuery',
  components: {
    Upload,
    BaseTable,
    moment
  },

  mixins: [formMixins],
  data() {
    return {
      dialogVisible: false,
      search: {
        file_name: '',
        upLoad: '',
        limit: 10,
        pageNum: 1
      },
      tableList: []
    }
  },

  computed: {
    ...mapGetters(['dictMap'])
  },
  mounted() {
    this.searchHandle()
  },
  methods: {

    dateFormat: function(row, column) {
      var date = row[column.property]
      // debugger
      if (date) {
        return moment(date).format('YYYY-MM-DD HH:mm')
      } else {
        return ''
      }
    },
    searchHandle() {
      this.dialogVisible = false
      const table = this.$refs['table']
      const search = _.extend(this.search)
      getFileList(Object.assign({}, search))
        .then(res => {
          table.complete().filData(res)
        })
        .catch(err => {
          table.complete()
        })
    },
    // 新增附件
    fileUpload() {
      this.dialogVisible = true
    },
    onCoverUpload(response) {
      console.log(response)
    }
  }
}
</script>

<style scoped>
  .content a {
    color: #409eff;
  }
</style>
